#include "Utility/FileSystem/SGFileSystem.h"

#include "DataStructure/Common/Constant.h"

#include "DBManager/IService/Input/Load/ILoadCombinationService.h"

#include "../MModel.h"

using SG::DataStructure::Common::TOLERANCE;
extern std::shared_ptr<DBServiceFactory> DB_SERVICEFACTORY;

// 测试ComputeBVector()函数能够处理LOAD中嵌套LOAD的情况
TEST (MModelTest, ComputeLoadVectorTest)
{
    // 搭建环境：BDF导入、model初始化等操作
    DB_SERVICEFACTORY->ClearDatabase ();
    SG::Import::SGImporter importer (DB_SERVICEFACTORY);
    auto                   fileName = SG::Utility::FileSystem::getTestDataPath ("SGFem/Pre/") + "StaticLin-LoadNested_fixed3.bdf";
    auto                   status   = importer.Import (fileName);
    ASSERT_EQ (status, Status::STATUS_Success);
    Kernel::MModel model (SOLType::SOL_SESTATIC, DB_SERVICEFACTORY);
    Id LoadId{11};
    model.Initialize ({ LoadId });
    RegisterElementCalculator ();
    model.CalcMatrixEquation (11);


    // 计算b荷载向量
    SG::FEMSolver::EigenVector bTest;
    model.ComputeLoadVector(LoadId, bTest);

    // 目标b值
    SG::FEMSolver::EigenVector bTarget (12);
    bTarget << 0.000000, 1339.800000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 3250.368000, 0.000000, 0.000000, 0.000000, 0.000000;

    //Check
    for (Eigen::Index idx{ 0 }; idx < bTest.size (); ++idx)
    {
        ASSERT_NEAR (bTest (idx), bTarget (idx), TOLERANCE);
    }
}